using System;
using System.Collections.Generic;
using System.IO;
using Common;
using Common.Enum;

namespace SProject.Paramter
{
	[Serializable]
	public class ADOption : BasicOption
	{
		private double _QualityThreshold = 0.8;

		private double _GainRatio = 0.9;

		private EADTypeMethod _TypeMethod = EADTypeMethod.Standart;

		public double QualityThreshold
		{
			get
			{
				return _QualityThreshold;
			}
			set
			{
				if (_QualityThreshold != value)
				{
					_QualityThreshold = value;
					OnPropertyChanged("QualityThreshold");
				}
			}
		}

		public double GainRatio
		{
			get
			{
				return _GainRatio;
			}
			set
			{
				if (_GainRatio != value)
				{
					_GainRatio = value;
					OnPropertyChanged("GainRatio");
				}
			}
		}

		public EADTypeMethod TypeMethod
		{
			get
			{
				return _TypeMethod;
			}
			set
			{
				if (_TypeMethod != value)
				{
					_TypeMethod = value;
					OnPropertyChanged("TypeMethod");
				}
			}
		}

		public override void Copy(BasicOption basicOption)
		{
			base.Copy(basicOption);
			ADOption aDOption = basicOption as ADOption;
			QualityThreshold = aDOption.QualityThreshold;
			GainRatio = aDOption.GainRatio;
			TypeMethod = aDOption.TypeMethod;
		}

		public override void SaveToStream(StreamEx stream)
		{
			base.SaveToStream(stream);
			List<PropertyKey> list = new List<PropertyKey>();
			List<byte[]> list2 = new List<byte[]>();
			list.Add(PropertyKey.Key_QualityThreshold);
			list2.Add(BytesConverter.GetBytes(QualityThreshold));
			list.Add(PropertyKey.Key_GainRatio);
			list2.Add(BytesConverter.GetBytes(GainRatio));
			list.Add(PropertyKey.Key_TypeMethod);
			list2.Add(BytesConverter.GetBytes((int)TypeMethod));
			stream.Write(PropertyKey.Key_Index);
			stream.WriteIndex(list, list2);
			stream.Flush();
		}

		public override bool ReadFromStream(StreamEx stream)
		{
			if (base.ReadFromStream(stream))
			{
				PropertyKey propertyKey = stream.ReadKey();
				if (propertyKey == PropertyKey.Key_Index)
				{
					List<PropertyKey> keys;
					List<byte[]> dates;
					stream.ReadIndex(out keys, out dates);
					for (int i = 0; i < keys.Count; i++)
					{
						switch (keys[i])
						{
						case PropertyKey.Key_QualityThreshold:
							QualityThreshold = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_GainRatio:
							GainRatio = BytesConverter.BytesToDouble(dates[i]);
							break;
						case PropertyKey.Key_TypeMethod:
							TypeMethod = (EADTypeMethod)BytesConverter.BytesToInt(dates[i]);
							break;
						}
					}
					return true;
				}
				stream.Seek(-4L, SeekOrigin.Current);
				while (true)
				{
					switch (stream.ReadKey())
					{
					case PropertyKey.Key_QualityThreshold:
						QualityThreshold = stream.ReadDouble();
						break;
					case PropertyKey.Key_GainRatio:
						GainRatio = stream.ReadDouble();
						break;
					case PropertyKey.Key_TypeMethod:
						TypeMethod = (EADTypeMethod)stream.ReadInt();
						break;
					default:
						stream.Seek(-4L, SeekOrigin.Current);
						return true;
					}
				}
			}
			return false;
		}
	}
}
